package com.sj.purchase.modules.cost.repository.imei;

import com.sj.purchase.modules.cost.domain.imei.UniqueCodes;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * 描述:
 * 作者: cuijh.
 * 包名：com.sj.purchase.modules.cost.repository.imei
 * 日期: 2018年03月17日 17:47
 * 项目名称: purchase
 * 版本: 1.0
 * JDK: since 1.8
 */
public interface UniqueCodesRepository extends JpaRepository<UniqueCodes,Integer>{

  Page<UniqueCodes> findByOutStockDateBetweenAndOrderIdIsNotNull(Date start, Date end, Pageable pageable);
  Page<UniqueCodes> findByOutStockDateBetween(Date start, Date end, Pageable pageable);
  @Transactional
  @Modifying
  @Query(value = "DELETE FROM t_unique_codes WHERE out_stock_date BETWEEN ?1 AND ?2", nativeQuery = true)
  void deleteAllByOutStockDateBetween(String startDate, String endDate);

  @Transactional
  @Modifying
  void deleteAllByOutStockDateBetweenAndOrderIdIsNull(Date start, Date end);
}
